<template>
 <div class="list" ref="wrapper">
    <div>
        <div class="area">
            <div class="title border-topbottom">当前城市</div>
            <div class="button-list">
                <div class="button-wrapper">
                   <div class="button">{{this.$store.state.city}}</div>
                 </div>
            </div>
        </div>
   
        <div class="area">
            <div class="title border-topbottom">热门城市</div>
            <div class="button-list">
                <div class="button-wrapper" v-for="item in hot" :key="item.id" @click="handleCityClick(item.name)">
                <div class="button">{{item.name}}</div>
                </div>
            </div>   
        </div>

            <div class="area" v-for="(item,key) in cities" :key="key" :ref="key">
                <div class="title border-topbottom">{{key}}</div>
                <div class="item-list">
                    <div class="item border-bottom" v-for="innerItem in item" :key="innerItem.id"
                     @click="handleCityClick(innerItem.name)">{{innerItem.name}}</div>
                </div>
            </div>
    </div>
 </div>
</template>

<script>
import BScroll from 'better-scroll'
export default {
    name:'CityList',
    props:{
        hot:Array,
        cities:Object,
        letter:String
    },
    mounted(){
        this.scroll =new BScroll(this.$refs.wrapper,{mouseWheel:true,click:true,tap:true});
    },
    watch:{
        letter (){
            if(this.letter){
                const element = this.$refs[this.letter][0]
                this.scroll.scrollToElement(element)
            }
        }
    },
      methods:{
         handleCityClick (city){   
         this.$store.commit('changeCity',city)     
  
         }
     }
}
</script>

<style scoped>
 .list{
    overflow:hidden;
    position:absolute;
    top:100px;
    left:0;
    right:0;
    bottom:0;
 }
   .title{
      line-height:25px;
      background:#eee;
      padding-left:12px;
      color:#666;
      font-size:14px;
      }
      
    .button-list{
        padding:1px 280px 1px 1px;
        overflow: hidden;
        width: 100%;
    }
    .button-wrapper{
        float:left; 
        width:30%;
    }
       
        .button{
          margin:8px;
          padding:3px 0;
          text-align:center;
          border:1px solid #ccc;
          border-radius:.06rem;
        }
         .item-list .item{
            padding-left:10px;
            line-height:20px;
            border-bottom:1px solid #ddd;
         }


</style>
